package com.ljm.boot.rabbitmq.config;
import com.ljm.boot.rabbitmq.constant.*;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

public class HeadersConfig {

    @Bean
    public Binding binding_header01() {
        Map<String,Object> map = new HashMap<>();
        map.put("color","red");
        map.put("speed","low");
        //whereAny(map): 只要发送的消息的属性 MessageProperties 有任意一个k-v匹配就 OK
        return BindingBuilder
                .bind(new Queue(RabbitMQConstant.HEADER_QUEUE_1))
                .to(new HeadersExchange(RabbitMQConstant.HEADER_EXCHANGE))
                .whereAny(map)
                .match();
    }

    @Bean
    public Binding binding_header02() {
        Map<String, Object> map = new HashMap<>();
        map.put("color", "red");
        map.put("speed", "fast");
        //whereAll(map): 发送的消息的属性 MessageProperties 要全部匹配才 OK
        return BindingBuilder
                .bind(new Queue(RabbitMQConstant.HEADER_QUEUE_2))
                .to(new HeadersExchange(RabbitMQConstant.HEADER_EXCHANGE))
                .whereAll(map)
                .match();
    }

}
